package com.day23.Consumer;


import java.util.function.Consumer;

import java.util.function.Consumer;

public class ConsumerTest {
    private static String str;
    public static void main(String[] args) {
        String[] strArray = {"林青霞,30", "张曼玉,35", "王祖蓝,33"};
        printInfo(strArray,
                str -> System.out.println(new StringBuilder()
                        .append("姓名：").append(str.split(",")[0])
                        .append(" 年龄：").append(str.split(",")[1]).toString()),
                age -> System.out.println("单独处理年龄：" + age));
    }

    private static void printInfo(String[] strArray, Consumer<String> con1, Consumer<Integer> con2) {
        for (String str : strArray) {
            String[] parts = str.split(",");
            con1.accept(str);
            try {
                int age = Integer.parseInt(parts[1]);
                con2.accept(age);
            } catch (NumberFormatException e) {
                System.err.println("年龄格式错误：" + parts[1]);
            }
        }
    }
}
